package kin.controller.system;

import java.util.ResourceBundle;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import kin.annotation.system.Button;
import kin.annotation.system.Module;
import kin.context.system.RequestContext;
import kin.manager.security.RoleManager;
import kin.service.security.RoleServiceManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.context.support.ResourceBundleMessageSource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.support.WebApplicationContextUtils;



@Controller
@RequestMapping("/role")
@Module(label="nav.role.controller",renderToNAV=true)
public class RoleController extends JsonController{
    @Inject
	private RoleServiceManager roleServiceManager;
    
    
    
    @ResponseBody
    @Module(label="nav.role.list",renderToNAV=true)
    @RequestMapping(value="/list", method=RequestMethod.GET)
	public Object list() throws Exception{
    	this.getResult().setObject(this.roleServiceManager.findAll());
    	ApplicationContext appCtx=WebApplicationContextUtils.getWebApplicationContext(RequestContext.getRequest().getSession().getServletContext());
    	//String ttt=messages.getMessage("label.button.add", new Object[]{},RequestContext.getRequest().getLocale());
    	String s=appCtx.getMessage("button.add", new Object[]{},RequestContext.getRequest().getLocale());
    	String v=appCtx.getMessage("button.list.add", new Object[]{},RequestContext.getRequest().getLocale());
    	/*ResourceBundleMessageSource message;
    	MessageSourceResolvable mes;
    	message.getMessage(resolvable, locale)*/
    	
    	/*String lang = RequestContextUtils.getLocale(RequestContext.getRequest()).getDisplayLanguage();
        ApplicationContext ctx = RequestContextUtils.getWebApplicationContext(RequestContext.getRequest());
        ResourceBundle resources = ResourceBundle.getBundle("message", RequestContext.getRequest().getLocale());*/
      
       /* String ss=resources.getString("label.button.add");
      String s=ctx.getMessage("label.button.add", new String[]{},RequestContext.getRequest().getLocale());*/
    	
    	
        //String s=ctx.getMessage("label.button.add", new Object[]{},"message",RequestContext.getRequest().getLocale());
    	//String v=ctx.getMessage("button.list.add", new Object[]{},RequestContext.getRequest().getLocale());
    	
		return this.getResult();
	}
    
  
    
    @ResponseBody
    @Module(label="nav.role.add",renderToNAV=true)
    @Button( label = "button.add",renderToActionColumn=true)
    @RequestMapping(value="/add", method=RequestMethod.POST)
    public Object add(){
      return this.getResult();
    }
    
    @ResponseBody
    @Module(label="nav.role.update")
    @Button( label = "button.update",renderToActionColumn=true)
    @RequestMapping(value="/update", method=RequestMethod.PUT)
    public Object update(){
    	//this.getResult().setObject(this.roleServiceManager.findAll());
    	return this.getResult();
    }
    
    
    	
    
  /*  @ResponseBody
    @Module(label="搜索")
    @Button( label = "搜索")
    @RequestMapping(value="/serach", method=RequestMethod.GET)
    public Object serach(){
    	
    	return null;
    }*/
    
    @ResponseBody
    @Module(label="nav.role.del")
    @Button( label = "button.del",renderToActionColumn=true)
    @RequestMapping(value="/delete", method=RequestMethod.DELETE)
    public Object delete(){
    	
    	return this.getResult();
    }

	public RoleServiceManager getRoleServiceManager() {
		return roleServiceManager;
	}

	public void setRoleServiceManager(RoleServiceManager roleServiceManager) {
		this.roleServiceManager = roleServiceManager;
	}



	



	

	
	
	
}
